home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
snip1292.zip
/
PRTOGGLE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-26
|
2KB
|
77 lines
/*
** prtoggle()
**
** Tee's all standard output to the printer.
**
** Parameters: None
**
** Returns: 0 if operation was successful.
** -1 if stdout or stdin is redirected.
**
** Side effects: Flushes the keyboard buffer
**
** Original Copyright 1988-1991 by Bob Stout as part of
** the MicroFirm Function Library (MFL)
**
** This subset version is functionally identical to the
** version originally published by the author in Tech Specialist
** magazine and is hereby donated to the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
int ungetkey(unsigned key)
{
int count;
#ifdef __ZTC__
peek(0x40, 0x1a, &head, sizeof(unsigned));
peek(0x40, 0x1c, &tail, sizeof(unsigned));
#else
head = peek(0x40, 0x1a);
tail = peek(0x40, 0x1c);
#endif
count = tail - head;
if (0 > count)
count += (16 * sizeof(unsigned));
count >>= 1;
if (15 > count)
{
#ifdef __ZTC__
peek(0x40, tail, &keystack[idx][0], sizeof(unsigned));
#else
keystack[idx][0] = peek(0x40, tail);
#endif
keystack[idx][1] = tail;
#ifdef __ZTC__
poke(0x40, tail, &key, sizeof(unsigned));
#else
poke(0x40, tail, key);
#endif
tail += sizeof(unsigned);
if (0x3e <= tail)
tail = 0x1e;
#ifdef __ZTC__
poke(0x40, 0x1c, &tail, sizeof(unsigned));
#else
poke(0x40, 0x1c, tail);
#endif
return key;
}
return EOF;
}
int cdecl prtoggle(void)
{
if (!isatty(fileno(stdin)) || !isatty(fileno(stdout)))
return -1;
while (kbhit()) /* Flush the keyboard buffer */
getch();
ungetkey('P' - 64); /* Stuff a Ctrl-P into the buffer */
system(""); /* Let COMMAND.COM do the work */
return 0;
}